package com.ss.android.article.base.ui;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.text.SpannableStringBuilder;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.b.ThreadPlus;
import com.bytedance.common.utility.collection.WeakHandler;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.app.BizApplication;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.model.VideoAlbumInfo;
import com.ss.android.article.base.feature.video.IVideoFullscreen;
import com.ss.android.article.base.utils.ArticleHelper;
import com.ss.android.article.browser.R;
import com.ss.android.common.dialog.WindowBase;
import com.ss.android.common.dialog.WindowBuilder;
import com.ss.android.common.util.NetworkStatusMonitor;
import com.ss.android.common.util.json.JsonUtil;
import com.ss.android.image.loader.ImageLoader;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.j.ClickableBackgroundCompat;
import com.ss.android.newmedia.BaseApplication;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

public final class at extends WindowBuilder implements IVideoFullscreen, DragDismissListView.a {
    final class at$a extends BaseAdapter {
        private final at b;
        private LayoutInflater a;

        public at$a(at arg2) {
            this.b = arg2;

            this.a = LayoutInflater.from(arg2.a);
        }

        public final int getCount() {
            return this.b.n.size();
        }

        public final Object getItem(int arg2) {
            return this.b.n.get(arg2);
        }

        public final long getItemId(int arg3) {
            return ((long) arg3);
        }

        public final View getView(int arg18, View arg19, ViewGroup arg20) {
            Object v2_5;
            ImageInfo v3_2;
            boolean v5_1;
            int v7;
            boolean v2_4;
            int v2_3;
            ax v8;
            View v6;
            View v2;
            boolean v12 = AppData.isNightMode();
            if (arg18 < 0 || arg18 >= this.b.n.size()) {
                v2 = null;
            } else {
                Object v11 = this.b.n.get(arg18);
                if (v11 == null) {
                    v2 = null;
                } else {
                    if (arg19 == null) {
                        arg19 = this.a.inflate(com.ss.android.article.browser.R.layout.related_videos_item, arg20, false);
                        ax v2_1 = new ax(this.b.a, this.b.d, this.b.i, this.b.j, this.b.g, this.b.h, this.b.f, this.b.e);
                        v2_1.b = arg19.findViewById(com.ss.android.article.browser.R.id.root);
                        v2_1.d = arg19.findViewById(com.ss.android.article.browser.R.id.divider);
                        v2_1.c = arg19.findViewById(com.ss.android.article.browser.R.id.title);
                        v2_1.i = arg19.findViewById(com.ss.android.article.browser.R.id.large_image_layout);
                        v2_1.j = arg19.findViewById(com.ss.android.article.browser.R.id.large_image);
                        v2_1.k = arg19.findViewById(com.ss.android.article.browser.R.id.right_image);
                        v2_1.l = arg19.findViewById(com.ss.android.article.browser.R.id.right_video_time);
                        v2_1.m = arg19.findViewById(com.ss.android.article.browser.R.id.large_video_time);
                        v2_1.n = arg19.findViewById(com.ss.android.article.browser.R.id.video_source);
                        v2_1.o = arg19.findViewById(com.ss.android.article.browser.R.id.comment_count);
                        v2_1.p = arg19.findViewById(com.ss.android.article.browser.R.id.right_video_icon);
                        v2_1.e = arg19.findViewById(com.ss.android.article.browser.R.id.multi_image_layout);
                        v2_1.f = arg19.findViewById(com.ss.android.article.browser.R.id.item_image_0);
                        v2_1.g = arg19.findViewById(com.ss.android.article.browser.R.id.item_image_1);
                        v2_1.h = arg19.findViewById(com.ss.android.article.browser.R.id.item_image_2);
                        ax.a(v2_1.f, v2_1.y, v2_1.z);
                        ax.a(v2_1.g, v2_1.y, v2_1.z);
                        ax.a(v2_1.h, v2_1.y, v2_1.z);
                        ax.a(v2_1.k, v2_1.y, v2_1.z);
                        v2_1.q = new ImageView[3];
                        v2_1.q[0] = v2_1.f;
                        v2_1.q[1] = v2_1.g;
                        v2_1.q[2] = v2_1.h;
                        v2_1.b.setOnClickListener(v2_1.E);
                        arg19.setTag(v2_1);
                        v6 = arg19;
                        v8 = v2_1;
                    } else {
                        v6 = arg19;
                        v8 = (ax) arg19.getTag();
                    }

                    if (v8 != null) {
                        ClickableBackgroundCompat.setClickableBackground(v6, v12);
                        long v2_2 = this.b.k;
                        int v4 = this.b.m.colNo;
                        if (v11 != null && ((Article) v11).groupId > 0) {
                            v8.r = ((Article) v11);
                            v8.C = v2_2;
                            v8.D = v4;
                            if (v8.r != null) {
                                if (v8.r.tags == null || (v8.r.tags.isEmpty())) {
                                    v8.c.setText(v8.r.title);
                                } else {
                                    v8.c.setText(android.support.design.a.a(v8.r.title, v8.r.tags, v8.u.getColor(com.ss.android.article.browser.R.color.update_comment_more_text_selector)));
                                }

                                TextView v3 = v8.c;
                                Resources v4_1 = v8.u;
                                v2_3 = v8.r.clickTimestamp > 0 ? R.color.c1 : R.color.ssxinzi2;
                                v3.setTextColor(v4_1.getColorStateList(v2_3));
                                v3 = v8.c;
                                v2_4 = v8.r.clickTimestamp <= 0 ? true : false;
                                v3.setEnabled(v2_4);
                            }

                            UIUtils.setVisibility(v8.i, 8);
                            UIUtils.setVisibility(v8.e, 8);
                            UIUtils.setVisibility(v8.k, 8);
                            UIUtils.setVisibility(v8.l, 8);
                            UIUtils.setVisibility(v8.m, 8);
                            if (v8.r != null && (v8.r.i())) {
                                AppData.isNightMode();
                                boolean[] v9 = new boolean[3];
                                Article v10 = v8.r;
                                int v12_1 = v8.t.mLoadImagePref;
                                boolean v13 = v8.v.isWifiOn();
                                boolean v14 = v8.v.isNetworkOn();
                                int v5 = 0;
                                v2_4 = true;
                                boolean v3_1 = true;
                                boolean v4_2 = true;
                                if (v10.largeImageList != null) {
                                    v5 = v8.x * v10.largeImageList.mHeight / v10.largeImageList.mWidth;
                                    if (v5 > v8.w) {
                                        v7 = v8.w;
                                    } else {
                                        v7 = v5;
                                    }
                                } else {
                                    label_647:
                                    v7 = v5;
                                }

                                if (v7 <= 0) {
                                    v2_4 = false;
                                }

                                if (v10.imageList == null || (v10.imageList.isEmpty())) {
                                    v3_1 = false;
                                }

                                if (v10.middleImage == null) {
                                    v4_2 = false;
                                }

                                if (!v13) {
                                    if ((v14) && v12_1 == 1) {
                                        if (v2_4) {
                                            v3_1 = false;
                                            v4_2 = v2_4;
                                            v2_4 = false;
//                                        goto label_424;
                                        } else if (v3_1) {
                                            v4_2 = v2_4;
                                            v2_4 = false;
//                                        goto label_424;
                                        } else {
                                            boolean v16 = v4_2;
                                            v4_2 = v2_4;
                                            v2_4 = v16;
                                        }
                                    } else if (!v14) {
                                        v5_1 = false;
                                        if (v3_1) {
                                            v2_4 = false;
                                            v4_2 = false;
//                                            goto label_424;
                                        } else {
                                            v2_4 = v4_2;
                                            v4_2 = v5_1;
                                        }
                                    } else {
                                        v5_1 = false;
                                        if (v4_2) {
                                            v3_1 = false;
                                            v2_4 = v4_2;
                                            v4_2 = false;
//                                            goto label_424;
                                        } else if (v3_1) {
                                            v2_4 = true;
                                            v3_1 = false;
                                            v4_2 = false;
//                                            goto label_424;
                                        } else {
                                            v2_4 = v4_2;
                                            v4_2 = v5_1;
                                        }
                                    }
                                } else {
                                    label_560:
                                    if (v2_4) {
                                        v3_1 = false;
                                        v4_2 = v2_4;
                                        v2_4 = false;
//                                        goto label_424;
                                    } else if (v3_1) {
                                        v4_2 = v2_4;
                                        v2_4 = false;
//                                        goto label_424;
                                    } else {
                                        boolean v16 = v4_2;
                                        v4_2 = v2_4;
                                        v2_4 = v16;
                                    }
                                }

                                label_424:
                                v9[0] = v4_2;
                                v9[1] = v3_1;
                                v9[2] = v2_4;
                                v5_1 = v9[0];
                                v2_4 = v9[1];
                                boolean v9_1 = v9[2];
                                if (v5_1) {
                                    UIUtils.setVisibility(v8.i, 0);
                                    ax.a(v8.j, 0, v7);
                                    v3_2 = v8.r.largeImageList;
                                    v8.j.setImageResource(com.ss.android.article.browser.R.drawable.cn);
                                    v8.j.setTag(com.ss.android.article.browser.R.id.image_info, v3_2);
                                    Drawable v3_3 = v8.j.getBackground();
                                    if (v3_3 != null) {
                                        v3_3.setLevel(0);
                                    }
                                }

                                if ((v2_4) && v8.r.imageList != null && !v8.r.imageList.isEmpty()) {
                                    UIUtils.setVisibility(v8.e, 0);
                                    v7 = v8.r.imageList.size();
                                    v2_5 = v8.r.imageList.get(0);
                                    Object v3_4 = null;
                                    Object v4_3 = v2_5 == null || v7 <= 1 ? v3_4 : v8.r.imageList.get(1);
                                    v3_2 = null;
                                    if (v4_3 != null && v7 > 2) {
                                        v3_4 = v8.r.imageList.get(2);
                                    }

                                    ax.a(v8.f, ((ImageInfo) v2_5));
                                    ax.a(v8.g, ((ImageInfo) v4_3));
                                    ax.a(v8.h, ((ImageInfo) v3_4));
                                }

                                ImageInfo v2_6 = v8.r.middleImage;
                                if (v2_6 == null && v8.r.imageList != null && !v8.r.imageList.isEmpty()) {
                                    v2_6 = (ImageInfo) v8.r.imageList.get(0);
                                }

                                if (!v9_1 || v2_6 == null) {
                                    if ((v8.r.h()) && (v5_1)) {
                                        UIUtils.setVisibility(v8.m, 0);
                                        if (v8.r.videoDuration > 0) {
                                            v8.m.setText(ArticleHelper.convert2ReadableString(v8.r.videoDuration), true);
                                        } else {
                                            v8.m.setText("", false);
                                            v8.m.a(com.ss.android.article.base.feature.app.a.b.i, true);
                                        }
                                    }

                                    v8.B = false;
                                } else {
                                    UIUtils.setVisibility(v8.k, 0);
                                    if (v8.r.h()) {
                                        UIUtils.setVisibility(v8.l, 0);
                                        UIUtils.setVisibility(v8.p, 8);
                                        UIUtils.setVisibility(v8.o, 0);
                                        if (v8.r.videoDuration > 0) {
                                            v8.l.setText(ArticleHelper.convert2ReadableString(v8.r.videoDuration), true);
                                        } else {
                                            v8.l.setText("", false);
                                            v8.l.a(com.ss.android.article.base.feature.app.a.b.i, true);
                                        }

                                        v8.o.setText(UIUtils.a(v8.r.videoWatchCount) + v8.s.getString(com.ss.android.article.browser.R.string.video_play_prefix));
                                        v8.n.setText(v8.r.source);
                                    }

                                    ax.a(v8.k, v2_6);
                                    v8.B = true;
                                }

                                v8.a();
                            }

                            v2_3 = v8.t.mFontSizePref;
                            if (v2_3 < 0 || v2_3 > 3) {
                                v2_3 = 0;
                            }

                            v8.c.setTextSize(((float) ax.a[v2_3]));
                            v2_3 = 0;
                            if (v8.B) {
                                v2_3 = ((int) v8.u.getDimension(R.dimen.fo));
                            }

                            v8.c.setPadding(0, 0, v2_3, 0);
                            if (v8.A != AppData.isNightMode()) {
                                v8.A = AppData.isNightMode();
                                v2_4 = v8.A;
                                ClickableBackgroundCompat.setClickableBackground(v8.b, v2_4);
                                if (v8.r.clickTimestamp > 0) {
                                    v8.c.setTextColor(v8.u.getColor(com.ss.android.article.browser.R.color.c1));
                                } else {
                                    v8.c.setTextColor(v8.u.getColor(com.ss.android.article.browser.R.color.ssxinzi2));
                                }

                                v8.d.setImageResource(com.ss.android.article.browser.R.color.hh);
                                v8.n.setTextColor(v8.u.getColorStateList(com.ss.android.article.browser.R.color.ssxinzi3));
                                v8.o.setTextColor(v8.u.getColorStateList(com.ss.android.article.browser.R.color.ssxinzi3));
                                UIUtils.setBackgroundResource(v8.p, R.drawable.detail_related_video_small_icon);
                                UIUtils.setBackgroundResource(v8.j, R.drawable.simple_image_holder_listpage);
                                UIUtils.setBackgroundResource(v8.f, R.color.t);
                                UIUtils.setBackgroundResource(v8.g, R.color.t);
                                UIUtils.setBackgroundResource(v8.h, R.color.t);
                                UIUtils.setBackgroundResource(v8.k, R.color.t);
                                v8.l.a(ContextCompat.getColorStateList(v8.s, R.color.ssxinzi8), false);
                                v8.l.setDrawable(ContextCompat.getDrawable(v8.s, R.drawable.palyicon_video_textpage), true);
                                v8.l.setBackgroundResource(com.ss.android.article.browser.R.drawable.video_time_length_bg);
                                v8.m.a(ContextCompat.getColorStateList(v8.s, R.color.ssxinzi8), false);
                                v8.m.setDrawable(ContextCompat.getDrawable(v8.s, R.drawable.palyicon_video_textpage), true);
                                v8.m.setBackgroundResource(com.ss.android.article.browser.R.drawable.video_time_length_bg);
                                ColorFilter v2_7 = v2_4 ? TTUtils.getNightModeColorFilter() : null;
                                v8.j.setColorFilter(v2_7);
                                v8.k.setColorFilter(v2_7);
                                v8.f.setColorFilter(v2_7);
                                v8.g.setColorFilter(v2_7);
                                v8.h.setColorFilter(v2_7);
                            }

                            v8.b.setPadding(0, v8.b.getPaddingTop(), 0, v8.b.getPaddingBottom());
                            v8.l.setDrawable((Drawable) null, false);
                        }

                        v8.d.setVisibility(View.GONE);
                        if (((Article) v11).groupId == this.b.k) {
                            v8.c.setTextColor(this.b.b.getColorStateList(com.ss.android.article.browser.R.color.update_comment_more_text_selector));
                            return v6;
                        }

                        v8.c.setTextColor(this.b.b.getColorStateList(com.ss.android.article.browser.R.color.ssxinzi2));
                    }

                    label_178:
                    v2 = v6;
                }
            }

            return v2;
        }
    }

    Context a;
    Resources b;
    WeakHandler c;
    public final NetworkStatusMonitor d;
    public final int e;
    public final int f;
    public final int g;
    public final int h;
    public ImageLoader i;
    public ImageLoader j;
    long k;
    public int l;
    final VideoAlbumInfo m;
    final List n;
    private TextView u;
    private ImageView v;
    private ImageView w;
    private TextView x;
    private DragDismissListView y;
    private at$a z;

    public at(Activity arg4, NetworkStatusMonitor arg5, ImageLoader arg6, ImageLoader arg7, int arg8, int arg9, int arg10, int arg11, long arg12, int arg14, VideoAlbumInfo arg15) {
        super(arg4);
        this.c = new WeakHandler(Looper.getMainLooper(), ((WeakHandler.Callback) this));
        this.n = new ArrayList();
        this.a = ((Context) arg4);
        this.b = arg4.getResources();
        AppData.getInstance();
        this.d = arg5;
        this.g = arg8;
        this.h = arg9;
        this.f = arg10;
        this.e = arg11;
        this.i = arg6;
        this.j = arg7;
        this.k = arg12;
        this.l = arg14;
        this.m = arg15;
        if ((arg4 instanceof com.ss.android.article.base.feature.detail2.cc)) {
            ((com.ss.android.article.base.feature.detail2.cc) arg4).a(((IVideoFullscreen) this));
        }
    }

    public final void a() {
        this.dismiss();
    }

    public final void a(Bundle arg10) {
        int v8 = R.color.ssxinzi3;
        int v7 = 33;
        super.a(arg10);
        this.u = (TextView) this.a(R.id.adj);
        this.v = (ImageView) this.a(R.id.adk);
        this.w = (ImageView) this.a(R.id.adl);
        this.y = (DragDismissListView) this.a(R.id.adm);
        this.x = (TextView) this.a(R.id.adn);
        this.y.setEmptyView(this.x);
        this.y.setOnDrag(this);
        this.v.setOnClickListener(new av(this));
        SpannableStringBuilder v0 = new SpannableStringBuilder();
        if (!android.support.design.a.isTextEmpty(this.m.title)) {
            v0.append(this.a.getString(com.ss.android.article.browser.R.string.df, new Object[]{this.m.title}));
            v0.append(" ");
        }

        if (!android.support.design.a.isTextEmpty(this.m.source)) {
            int v1 = v0.length();
            v0.append(this.m.source);
            v0.setSpan(new AbsoluteSizeSpan(((int) (this.u.getTextSize() - 5f))), v1, v0.length(), v7);
            Resources v3 = this.b;
            AppData.isNightMode();
            v0.setSpan(new ForegroundColorSpan(v3.getColor(v8)), v1, v0.length(), v7);
        }

        this.u.setText(((CharSequence) v0), TextView.BufferType.SPANNABLE);
        if (AppData.isNightMode()) {
            this.q.setBackgroundResource(com.ss.android.article.browser.R.color.ssxinmian2);
            this.u.setTextColor(this.b.getColorStateList(v8));
            this.v.setBackgroundResource(com.ss.android.article.browser.R.drawable.nl);
            this.w.setImageResource(com.ss.android.article.browser.R.color.hh);
            if (this.z != null) {
                this.z.notifyDataSetChanged();
            }
        }

        if (this.m == null || (android.support.design.a.isTextEmpty(this.m.url))) {
            this.dismiss();
        } else {
            new ThreadPlus(new aw(this), "video_album,", true).start();
        }
    }

    public final ViewGroup b() {
        if (this.q == null) {
            this.q = (ViewGroup) LayoutInflater.from(BizApplication.getApplication()).inflate(R.layout.jd, null);
        }

        return this.q;
    }

    public final WindowBase c() {
        if (this.p == null) {
            this.p = new au(BaseApplication.getApplication());
        }

        return this.p;
    }

    public final void handleMsg(Message message) {
        int v1_1;
        Article v1;
        int v11 = 3;
        super.handleMsg(message);
        switch (message.what) {
            case 10: {
                if ((message.obj instanceof JSONArray)) {
                    Object v0 = message.obj;
                    if (v0 != null && ((JSONArray) v0).length() >= 0) {
                        int v9 = ((JSONArray) v0).length();
                        this.n.clear();
                        int v7 = -1;
                        int v8 = 0;
                        while (v8 < v9) {
                            try {
                                JSONObject v10 = ((JSONArray) v0).getJSONObject(v8);
                                long v2 = v10.optLong("group_id");
                                if (v2 > 0) {
                                    v1 = new Article(v2, v10.optLong("item_id"), v10.optInt("aggr_type"));
                                    JsonUtil.parseJSONObject(v10, v1);
                                    if (v2 != this.k) {
                                        this.n.add(v1);
                                        v1_1 = v7;
                                        ++v8;
                                        v7 = v1_1;
                                        continue;
                                    }
                                } else {
                                    v1_1 = v7;
                                    ++v8;
                                    v7 = v1_1;
                                    continue;
                                }
                            } catch (Exception v0_1) {
                                break;
                            }
                        }

                        if (this.z == null) {
                            this.z = new at$a(this);
                            this.y.setAdapter(this.z);
                        } else {
                            this.z.notifyDataSetChanged();
                        }

                        if (v7 <= v11) {
//                    goto label_12;
                        } else if (v7 >= this.n.size()) {
//                    goto label_12;
                        } else {
                            if (v7 > this.n.size() - 3) {
                                this.y.setSelection(this.y.getBottom());
                            } else if (v7 > v11) {
                                v7 += -2;
                            }

                            this.y.setSelection(v7);
                            this.z.notifyDataSetInvalidated();
                        }
                    }

                    label_12:
                    this.x.setText(com.ss.android.article.browser.R.string.ss_error_unknown);
                }
            }
        }

        return;
    }

    public final void onFullscreenChanged(boolean arg1) {
        this.dismiss();
    }
}

